@include('admin.public.head')

<style type="text/css">
    .ibox-title{
        float: left;
    }
    .class_base{
        position: relative;
        width: 70%;
        height: 200px;
        overflow-x: hidden;
        overflow-y: scroll;
        text-align: left;
        margin-bottom-bottom: 15px;
        float: left;
        margin-bottom: 15px;
        margin-top: 15px;
        font-size:14px
    }
    .class_base p{
        font-weight: bold;
    }
    .class_base p span{
        color:red;
    }
    .class_base::-webkit-scrollbar{
        display: none;
    }
    .span_c{
       padding-right: 20px;
    }
</style>

<div class="ibox-title">
    <h5>camp编辑</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">团购商品名称：</label>
            <div class="col-sm-9">
                <input type="text" name="group_class_name" class="form-control"  value="{{$result->group_class_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">需要多少积分购买：</label>
            <div class="col-sm-9">
                <input type="number" name="group_class_price" class="form-control"  value="{{$result->group_class_price??'0'}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">该套餐可购买（预约）量：</label>
            <div class="col-sm-9">
                <input type="number" name="buy_number" class="form-control"  value="{{$result->buy_number??'0'}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">trx进阶：</label>
            <div class="col-sm-9">
                <script id="trx" name="trx" type="text/plain" style="height:300px;">{!! $result->trx??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">适合人群：</label>
            <div class="col-sm-9">
                <script id="crowd" name="crowd" type="text/plain" style="height:300px;">{!! $result->crowd??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">注意事项：</label>
            <div class="col-sm-9">
                <script id="points" name="points" type="text/plain" style="height:300px;">{!! $result->points??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">补堂规定：</label>
            <div class="col-sm-9">
                <script id="make_up_rules" name="make_up_rules" type="text/plain" style="height:300px;">{!! $result->make_up_rules??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">圖片：</label>
            <div class="col-sm-9">
                <input type="file" name="cove_img" class="form-control"  value="">
                <img src="{{$result->cove_img??''}}" width="300" height="150">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">門店分類：</label>
            <div class="col-sm-9">
                <select class="form-control" name="store_id" id="store_id">
                    <option value="" >請選擇門店</option>
                    @foreach($select_store as $k=>$v)
                        <option value="{{$k}}" @if($select_id == $k) selected="selected" @endif>{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">课程安排：</label>
            <div class="col-sm-9 class_base" id="class_base_arrange">
                @foreach($reservation_lists as $k=>$v)
                    <p>
                        <input type="checkbox" class="" name="class_base_info_id" value="{{$v['id']}}" @if(isset($group_class_info)) @if(in_array($v['id'],$group_class_info))  checked  @endif @endif>&nbsp;&nbsp;
                        <span>門店名稱</span>：<em class="span_c">{{$v['store']['store_name']}}</em><span>課室</span>：<em class="span_c">{{$v['classsroom']['numbering']}}</em><span>教師</span>：<em class="span_c">{{$v['teacher']['teacher_name']}}</em><span>課程</span>：<em class="span_c">{{$v['class_base']['class_name']}}</em><span>周期</span>：<em class="span_c">{{$v['class_week']}}</em><span>時段</span>：<em class="span_c">{{$v['class_time']['time_start']}}~{{$v['class_time']['time_end']}}</em><span>季度</span>：<em class="span_c">{{$v['quarterly']['name']}}</em>
                    </p>
                @endforeach
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">允许补课次数：</label>
            <div class="col-sm-9">
                <input type="text" name="remedial_teaching_number" class="form-control"  value="{{$remedial_teaching_number??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">报名开始时间：</label>
            <div class="col-sm-9">
                <input type="text" name="registration_start_time" id="registration_start_time" class="form-control"  value="{{$result->registration_start_time??''}}" autocomplete="off" >
            </div>
        </div>

        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">报名最后时间：</label>
            <div class="col-sm-9">
            <input type="text" name="registration_time" id="registration_time" class="form-control"  value="{{$result->registration_time??''}}" autocomplete="off" >
            </div>
        </div>

        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上课开始时间：</label>
            <div class="col-sm-9">
                @php
                    if(!empty($result->start_time)){
                        $result->start_time = explode(' ',$result->start_time)[0];
                    }
                @endphp
                <input type="text" name="start_time" id="start_time" class="form-control"  value="{{$result->start_time??''}}" autocomplete="off" >
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上课结束时间：</label>
            <div class="col-sm-9">
                @php
                    if(!empty($result->end_time)){
                        $result->end_time = explode(' ',$result->end_time)[0];
                    }
                @endphp
                <input type="text" name="end_time" id="end_time" class="form-control"  value="{{$result->end_time??''}}" autocomplete="off" >
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/camp" class="btn btn-primary" >返回camp列表</a>
            </div>
        </div>
    </form>
</div>
<script>

    laydate.render({
        elem: '#registration_time',
        min: '', //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: true,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    });


    laydate.render({
        elem: '#registration_start_time',
        min: '', //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: true,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    });

    var trx_content = UE.getEditor('trx');
    var crowd_content = UE.getEditor('crowd');
    var points_content = UE.getEditor('points');
    var make_up_rules_content = UE.getEditor('make_up_rules');

    $('.do').click(function(){

        var form = new FormData();

        var id = $('input[name="id"]').val();

        var store_id = $('#store_id option:selected').val();
        var group_class_name = $('input[name="group_class_name"]').val();
        var group_class_price = $('input[name="group_class_price"]').val();
        var buy_number = $('input[name="buy_number"]').val();
        var trx = trx_content.getContent();
        var crowd = crowd_content.getContent();
        var points = points_content.getContent();
        var make_up_rules = make_up_rules_content.getContent();
        var cove_img = $('input[name="cove_img"]')[0].files[0];
        var remedial_teaching_number = $("input[name='remedial_teaching_number']").val();
        var start_time = $('input[name="start_time"]').val();
        var registration_time = $('input[name="registration_time"]').val();
        var registration_start_time = $('input[name="registration_start_time"]').val();
        var end_time = $('input[name="end_time"]').val();

        var class_base_info_id = new Array();

        $("input[name='class_base_info_id']:checked").each(function(){
            class_base_info_id.push($(this).val());
        });

        $("input[name='class_base_info_id']:checked").each(function(){
            class_base_info_id.push($(this).val());
        });

        if(class_base_info_id.length == 0){
            var swal_json = {
                title: '请选择课程',
                type: "error"
            }

            swal(swal_json, function (isConfirm) {

            });

            return false;
        }

        form.append("cove_img", cove_img);
        form.append("store_id", store_id);
        form.append("id", id);
        form.append("group_class_name", group_class_name);
        form.append("group_class_price", group_class_price);
        form.append("make_up_rules", make_up_rules);
        form.append("registration_time", registration_time);
        form.append("registration_start_time", registration_start_time);
        form.append("buy_number", buy_number);
        form.append("trx", trx);
        form.append("crowd", crowd);
        form.append("points", points);
        form.append("class_base_info_id", class_base_info_id);
        form.append("remedial_teaching_number", remedial_teaching_number);
        form.append("start_time", start_time);
        form.append("end_time", end_time);

        $.ajax({
            type: 'POST',
            url: '/camp_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){
                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;

    });

    $("#store_id").change(function(){
        var form = new FormData();

        var store_id = $('#store_id option:selected').val();
        var id = $('input[name="id"]').val();

        form.append("store_id", store_id);
        form.append("id", id);

        $.ajax({
            type: 'POST',
            url: '/camp_reservation_lists' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){
                var reservation_lists = data.data.reservation_lists;
                var group_class_info = data.data.group_class_info;

                $("#class_base_arrange").html('');

                var html = '';

                for(var i in reservation_lists) {
                    html += '<p>';
                    html += '<input type="checkbox" class="" name="class_base_info_id" value="'+reservation_lists[i].id+'" ';

                    var index = group_class_info.indexOf(reservation_lists[i].id);

                    if(index != -1){
                        html += 'checked';
                    }

                    html += '>&nbsp;&nbsp;';
                    html += '<span>門店名稱</span>：<em class="span_c">'+reservation_lists[i].store.store_name+'</em><span>課室</span>：<em class="span_c">'+reservation_lists[i].classsroom.numbering+'</em><span>教師</span>：<em class="span_c">'+reservation_lists[i].teacher.teacher_name+'</em><span>課程</span>：<em class="span_c">'+reservation_lists[i].class_base.class_name+'</em><span>周期</span>：<em class="span_c">'+reservation_lists[i].class_week+'</em><span>時段</span>：<em class="span_c">'+reservation_lists[i].class_time.time_start+'~'+reservation_lists[i].class_time.time_end+'</em><span>季度</span>：<em class="span_c">'+reservation_lists[i].quarterly.name+'</em>';
                    html += '</p>';
                }

                $("#class_base_arrange").html(html);
            }
        });
    });
</script>
@include('admin.public.laydate')
